/* 
 * File:   XWindow.h
 * Author: ucho
 * Created on July 28, 2008, 7:49 PM
 */

#include "XDisplay.h"
#include <X11/Xlib.h> 
#include <X11/Xatom.h>

#ifndef _XWINDOW_H
#define	_XWINDOW_H
class XWindow {
public:
	XWindow(XDisplay* display): display_(display), window_(createDummy(display)) {};
	XWindow(XDisplay* display, Window window): display_(display), window_(window) {};
	void map() {
		XMapWindow(display_->getRawHandler(), window_);
	}
	
	XDisplay * getDisplay() {
		return this->display_;
	}
	std::string* getProperty(Atom property) {
		return display_->getWindowProperty(window_, property);
	}
	Window getRawHandler() {
		return window_;
	}
	void selectInputMask(long int mask) {
		display_->selectInput(window_, mask);
	}
	void takeOverSelection(Atom selection) {
		display_->setSelectionOwner(selection, window_);
	}
private:
	static Window createDummy(XDisplay* display) {
		Display * handler = display->getRawHandler();
		Window parent = DefaultRootWindow(handler);
		//std::cout << "creating window on display:" << handler << endl;
		Window result = XCreateSimpleWindow(handler, parent, 0, 0, 1, 1, 0, 0, 0);
		//std::cout << "Created, id =" << result << endl;
		return result;
	};
	
	XDisplay *display_;
	Window window_;
};


#endif	/* _XWINDOW_H */

